package com.kotlin.library.ui.activity

import android.os.Bundle
import com.kotlin.library.common.BaseApplication
import com.kotlin.library.injection.component.ActivityComponent
import com.kotlin.library.injection.component.DaggerActivityComponent
import com.kotlin.library.injection.module.ActivityModule
import com.kotlin.library.injection.module.LifecycleProvidesModule
import com.kotlin.library.presenter.BasePresenter
import com.kotlin.library.presenter.view.BaseView
import javax.inject.Inject

/**
 *
 * USER: zjw
 * DATA: 2018/11/27 0027
 * TIME: 下午 3:58
 * BaseMvpActivity 是用到mvp的Activity所需要集成的类,里面有BasePresenter的应用,和实现baseView
 */
abstract class BaseMvpActivity<T : BasePresenter<*>> : BaseActivity(), BaseView {
    override fun showLoading() {
    }

    override fun hideLoading() {
    }

    override fun onError() {
    }

    @Inject
    lateinit var mPresenter: T
    lateinit var activityComponent: ActivityComponent
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        initInjection()

        //抽像方法,每个子类都需要注册下dagger2
        initInject()
    }

    abstract fun initInject()

    private fun initInjection() {
        activityComponent =
                DaggerActivityComponent.builder()
                    .appComponent((application as BaseApplication).appComponent)
                    .activityModule(ActivityModule(this))
                    .lifecycleProvidesModule(LifecycleProvidesModule(this))
                    .build()
    }
}